<?php
session_start();//开启session会话
//error_reporting(E_ALL);//屏蔽错误
use Phalcon\Config;
use Phalcon\Loader;
use Phalcon\Tag;
use Phalcon\Mvc\Url;
use Phalcon\Mvc\View;
use Phalcon\Mvc\Application;
use Phalcon\DI\FactoryDefault;
use Phalcon\Db\Adapter\Pdo\Mysql as DbAdapter;
use Phalcon\Session\Adapter\Files as Session;

try {
    define('APP_PATH', realpath('..') . '/');
    // Register an autoloader
    $loader = new Loader();
    $loader->registerDirs(
        array(
            APP_PATH.'app/controllers/',
            APP_PATH.'app/models/',
            APP_PATH.'app/common/',
            APP_PATH.'app/forms/'
        )
    )->register();    


    // Create a DI
    $di = new FactoryDefault();

    // Setting up the view component
    $di['view'] = function() {
        $view = new View();
        $view->setViewsDir('../app/views/');
        return $view;
    };

    // Setup a base URI so that all generated URIs include the "tutorial" folder
    $di['url'] = function() {
        $url = new Url();
        $url->setBaseUri('/TeClan/');
        return $url;
    };

    // Setup the tag helpers
    $di['tag'] = function() {
        return new Tag();
    };

    // Start the session the first time when some component request the session service
    $di->setShared('session', function () {
        $session = new Session();
        $session->start();
        return $session;
    });

    $di['db'] = function() {
        require_once(APP_PATH.'app/common/db.php');
		$config = new Config($database);
        //return $config;//程序报错解决  Exception: Call to undefined method Phalcon\Config::tableexists()
        return new DbAdapter((array)$config);
    };
    // Handle the request
    $application = new Application($di);

    echo $application->handle()->getContent();

} catch (Exception $e) {
     echo "Exception: ", $e->getMessage();
}
